package com.naiterui.ehp.bs.pharmacist.utils;

import com.naiterui.common.redis.RedisUtil;
import com.naiterui.ehp.bp.constants.CommonConstant;
import com.naiterui.ehp.bp.utils.lang.ConfigUtil;
import com.naiterui.ehp.bs.pharmacist.vo.user.AuthRegistCacheVO;

/**
 * @Description TODO
 * @Author gongbaoqiang
 * @Date 2019/12/2 11:36 AM
 */
public class Constants {
    /**
     * redis key:注册，获取短信验证码
     */
    public static final String PHONE_REGIST_KEY = CommonConstant.REDIS_PRE_PHARMACIST + "ph_rg_";
    /**
     * redis key:忘记密码，获取短信验证码
     */
    public static final String PHONE_FORGET_KEY = CommonConstant.REDIS_PRE_PHARMACIST + "ph_fg_";
    /**
     * redis key:修改手机，获取短信验证码
     */
    public static final String PHONE_MODIFY_PHONE_KEY = CommonConstant.REDIS_PRE_PHARMACIST + "ph_myph_";
    /**
     * redis key:修改密码，获取短信验证码
     */
    public static final String PHONE_MODIFY_PWD_KEY = CommonConstant.REDIS_PRE_PHARMACIST + "ph_mypwd_";
    /**
     * redis key:登录验证码，获取短信验证码
     */
    public static final String PHONE_LOGIN_PWD_KEY = CommonConstant.REDIS_PRE_PHARMACIST + "ph_login_";
    /**
     * redis key:电子签名密码
     */
    public static final String PHONE_ESIGN_PWD_KEY = CommonConstant.REDIS_PRE_PHARMACIST + "ph_esign_pwd_";
    /**
     * 忘记密码短信验证通过key
     */
    public static final String PHONE_VALID_FORGET_KEY = CommonConstant.REDIS_PRE_PHARMACIST + "forget_verfiy_";


    /**
     * 注册短信验证通过key
     */
    public static final String PHONE_VALID_REGIST_KEY = CommonConstant.REDIS_PRE_PHARMACIST + "regist_verfiy_";

    /**
     * redis key:登陆私钥的loginKey
     */
    public static final String PHARMACIST_LOGIN_KEY = CommonConstant.REDIS_PRE_PHARMACIST + "loginKey_";
    /**
     * redis key:登陆成功的token key
     */
    public static final String PHARMACIST_LOGIN_TOKEN_KEY = CommonConstant.REDIS_PRE_PHARMACIST + "login_token_";
    /**
     * 药师登录是否互踢，存在就是不互踢
     */
    public static final String PHARMACIST_LOGIN_KICK_EACH_OTHER =
            CommonConstant.REDIS_PRE_PHARMACIST + "kick_each_other";

    /**
     * redis key:电子签名密码是否已设置
     */
    public static final String PHARMACIST_ESIGN_PWD_SET_KEY = CommonConstant.REDIS_PRE_PHARMACIST + "esign_pwd_set_";


    /**
     * 医生账户禁用状态
     */
    public static final int PHARMACIST_ACCOUNT_STATUS_DISABLE = 1;

    /**
     * redis key:注册，短信发送时间记录，用户60秒间隔控制
     */
    public static final String PHONE_SEND_TIME_KEY = CommonConstant.REDIS_PRE_PHARMACIST + "ph_send_";
    /**
     * redis key:注册，短信发送时间记录，用户每天10条发送量控制
     */
    public static final String PHONE_SEND_COUNT_KEY = CommonConstant.REDIS_PRE_PHARMACIST + "ph_count_";
    /**
     * redis key:注册，短信发送当天时间记录，用于限制用户每天10条发送量控制
     */
    public static final String PHONE_DAY_SEND_COUNT_KEY = CommonConstant.REDIS_PRE_PHARMACIST + "ph_day_count_";

    // 验证码错误规则的redis key
    public static final String VALID_KEY = CommonConstant.REDIS_PRE_PHARMACIST + "valid_exp";
    // 验证码错误规则的redis key的count字段以及默认值
    public static final String VALID_COUNT_FIELD = "count";
    public static final int DEFAULT_COUNT_FIELD = 20;
    // 验证码错误规则的redis key的time字段以及默认值
    public static final String VALID_TIME_FIELD = "time";
    public static final int DEFAULT_TIME_FIELD = 10 * 60;

    /**
     * 登录失败次数
     */
    public static final int LOGIN_FAIL_COUNT = 5;

    /**
     * 登录失败
     */
    public static final int LOGIN_FAIL_LOCK_TIME = 30 * 60;

    // 验证码有效期
    public static final int SAVE_VERIFY_CODE = 10 * 60;
    // 发送验证码
    public static final int MINTER = 60;
    // 短信发送间隔时间
    public static final int SEND_SPACE = 55;
    // 验证码发送次数限制
    public static final int SEND_MAX_COUNT = 10;

    /**
     * 药师审核处方锁键前缀
     */
    public static final String RECOM_PHARMACIST_AUDIT_LOCK_KEY = CommonConstant.REDIS_PRE_PHARMACIST + "recom_audit_";

    /**
     * redis key：获取短信验证错误后的操作key
     */
    public static String getSmsValidUserOperatorKey(String cacheKey) {
        return cacheKey + "|key";
    }

    /**
     * redis key登陆失败计数
     */
    public static String getLoginFailKey(Long loginId) {
        return CommonConstant.REDIS_PRE_PHARMACIST + "login_fail_count|" + loginId;
    }

    /**
     * 腾讯人脸实名
     */
    public static final String RDS_DETECT = CommonConstant.REDIS_PRE_PHARMACIST + "detect_";

    /**
     * 人脸实名认证操作标记 key
     */
    public static final String RDS_REALNAME_AUTH_STATUS_CACHE = Constants.RDS_DETECT + "realname_auth_status_";

    /**
     * 文件域名
     */
    public final static String EHP_DOMAIN_IMG = ConfigUtil.getString("ehp.domain.img");

    /**
     * 药师签名图片路径
     */
    public static final String SEAL_PATH_PRE_PH = ConfigUtil.getString("esign.seal.path") + "ph/";

    /**
     * 文件存储根路径
     */
    public  static  final String FILE_BASE_PATH = ConfigUtil.getString("file.base.prefix");

    /**
     * 药师密码最后修改时间
     */
    public  static  final String RDS_KEY_LAST_MODIFY = CommonConstant.REDIS_PRE_PHARMACIST + "lastModify_";


    public static final boolean getRdsRealnameAuthStatus(Long doctorId) {
        return RedisUtil.keyOps().existsKey(RDS_REALNAME_AUTH_STATUS_CACHE + doctorId);
    }

    public static final void setRdsRealnameAuthStatus(Long doctorId) {
        RedisUtil.valueOps().set(RDS_REALNAME_AUTH_STATUS_CACHE + doctorId, 1, 10 * 60);
    }

    public static final void removeRdsRealnameAuthStatus(Long doctorId) {
        RedisUtil.keyOps().delete(RDS_REALNAME_AUTH_STATUS_CACHE + doctorId);
    }

    public static final void setRdsAuthId(Long userId, String authId) {
        RedisUtil.valueOps().setString(CommonConstant.REDIS_PRE_PHARMACIST + "authId_" + userId, authId);
    }

    public static final String getRdsAuthId(Long userId) {
        return RedisUtil.valueOps().getString(CommonConstant.REDIS_PRE_PHARMACIST + "authId_" + userId);
    }

    public static final void removeRdsAuthId(Long userId) {
        RedisUtil.keyOps().delete(CommonConstant.REDIS_PRE_PHARMACIST + "authId_" + userId);
    }

    public static final void setRdsAuthUuid(Long userId, String uuid) {
        RedisUtil.valueOps().setString(CommonConstant.REDIS_PRE_PHARMACIST + "auth_uuid_" + userId, uuid);
    }

    public static final String getRdsAuthUuid(Long userId) {
        return RedisUtil.valueOps().getString(CommonConstant.REDIS_PRE_PHARMACIST + "auth_uuid_" + userId);
    }

    public static final void delRdsAuthUuidKey(Long userId) {
        RedisUtil.keyOps().delete(CommonConstant.REDIS_PRE_PHARMACIST + "auth_uuid_" + userId);
    }

    /**
     * 设置认证流程Id
     * 
     * @param authId
     */
    public static final void setRdsPhAuthId(String authId, AuthRegistCacheVO authRegistCache) {
        RedisUtil.valueOps().set(CommonConstant.REDIS_PRE_PHARMACIST_AUTHID_CACHE_KEY + authId, authRegistCache, 10 * 60);
    }

    /**
     * 获取认证流程Id
     *
     * @param authId
     */
    public static final AuthRegistCacheVO getRdsPhAuthId(String authId) {
        AuthRegistCacheVO object =(AuthRegistCacheVO) RedisUtil.valueOps().getObject(CommonConstant.REDIS_PRE_PHARMACIST_AUTHID_CACHE_KEY + authId);
        if (null == object) {
            return null;
        }
        return object;
    }

    /**
     * 删除认证流程Id
     *
     * @param authId
     */
    public static final void delRdsPhAuthId(String authId) {
        RedisUtil.keyOps().delete(CommonConstant.REDIS_PRE_PHARMACIST_AUTHID_CACHE_KEY + authId);
    }

    /**
     * 设置认证流程Id是否验证过实名
     *
     * @param authId
     */
    public static final void setRdsPhAuthIdCheck(String authId, String code) {
        RedisUtil.valueOps().set(CommonConstant.REDIS_PRE_PHARMACIST_AUTHID_CHECK_CACHE_KEY + authId, code, 10 * 60);
    }

}
